package ie.lawlor.amvc.component.button;

import ie.lawlor.amvc.swing.JPanelView;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;


/**
 * @author blawlor
 *
 */
public class ButtonView extends JPanelView {

	/**
	 * Comment for <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 4122819188021801269L;

  private String payload;
	public ButtonView(){
		setLayout(new BorderLayout());
		button = new JButton();
		add(BorderLayout.CENTER, button);
		initEvents();
	}
	
    public void initEvents(){
		button.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e){
				buttonActionPerformed(e);
			}
		});
	}
	
	private void buttonActionPerformed(ActionEvent e){
    logger.debug("Firing Button OK event from view with payload " + payload);
		fire(getController().getEvent("buttonOkEvent"), payload);
	}
	
	public void setName(String name){
		super.setName(name);
		button.setLabel(name);
	}
	
  public String getPayload() {
    return payload;
  }
  public void setPayload(String payload) {
    this.payload = payload;
  }
	private JButton button;
}
